home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / pas_0593.zip / SPLTFILE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-30  |  3KB  |  98 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 132 of 345
  3. From : Eric Miller                         1:387/307.0          23 May 93  20:58
  4. To   : Stephen Cheok
  5. Subj : SPLITTING FILES
  6. ────────────────────────────────────────────────────────────────────────────────
  7.  quoted from carbon unit Stephen Cheok to All
  8.   about SPLITTING FILES on 05-21-93  16:26
  9.  
  10.  
  11.  SC> Hi!  I was wondering.  How would you in Turbo Pascal be able
  12.  SC> to split a single file into two.  I want it to split it to a precise
  13.  SC> byte for both files.  I want to be able to combine to files together
  14.  SC> and split it to its original sizes and still be able to work (that no
  15.  SC> codes are missing etc.).  Help..  Thanx..
  16.  
  17.  
  18.  
  19.      Well, what you do is read in parts of the original to the
  20.    first file to a certain point, and then from there write them
  21.    to the second file, and so on.  the following code works, but
  22.    is terribly ineffecient, etc...           }
  23.  
  24. PROGRAM SplitFile;
  25.  
  26. VAR
  27.   infile,
  28.   outfile1,
  29.   outfile2: File;
  30.  
  31.   orig_size, readd, count,
  32.   buffer_size, file1_size, file2_size: longint;
  33.  
  34.   pbuf: pointer;
  35.  
  36.   orig_file, out_file1, out_file2: string;
  37.  
  38. BEGIN
  39.  
  40.   Write('Enter original filename: ');
  41.   Readln(orig_file);
  42.  
  43.   Assign(infile, orig_file);
  44.   Reset(infile,1);
  45.   orig_size := filesize(infile);
  46.  
  47.  
  48.   Write('Enter outfile 1 filename: ');
  49.   Readln(out_file1);
  50.   Write('  Enter size (',orig_size,' max): ');
  51.   Readln(file1_size);
  52.   Write('Enter outfile 2 filename: ');
  53.   Readln(out_file2);
  54.   Write('  Enter size (',orig_size-file1_size,' max): ');
  55.   Readln(file2_size);
  56.  
  57.   Assign(outfile1, out_file1);
  58.   Rewrite(outfile1,1);
  59.   Assign(outfile2, out_file2);
  60.   Rewrite(outfile2,1);
  61.  
  62.  
  63.   { init }
  64.  
  65.   readd := 0;
  66.   buffer_size := 4096; { max bytes to read in at a time }
  67.   getmem(pbuf, buffer_size);
  68.  
  69.   { outfile1 }
  70.  
  71.   WHILE (Readd < file1_size) DO
  72.     BEGIN
  73.       count := file1_size - readd; { bytes left to read }
  74.       IF count > buffer_Size then count := buffer_size;  { too much for buf? }
  75.       Writeln('Reading ', count, ' bytes...');
  76.       Blockread(infile, pbuf^, count);
  77.       blockwrite(outfile1, pbuf^, count);
  78.       inc(readd, count);
  79.     END;
  80.  
  81.   { outfile1 }
  82.  
  83.   readd := 0;
  84.  
  85.   WHILE (Readd < file2_size) DO
  86.     BEGIN
  87.       count := file2_size - readd;
  88.       IF count > buffer_Size then count := buffer_size;
  89.       Writeln('Reading ', count, ' bytes...');
  90.       Blockread(infile, pbuf^, count);
  91.       blockwrite(outfile2, pbuf^, count);
  92.       inc(readd, count);
  93.     END;
  94.  
  95.   Close(infile);
  96.   Close(outfile1);
  97.   Close(outfile2);
  98. END.